<?php

namespace App\Jobs;

use App\Services\AttachmentService;
use App\Services\CommonService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;


class DelOssPdf implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected  $fileUrl;
    protected  $pdfTable;
    protected  $pdfId;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($pdfTable, $pdfId, $fileUrl)
    {
        $this->pdfTable = $pdfTable;
        $this->pdfId    = $pdfId;
        $this->fileUrl  = $fileUrl;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        (new AttachmentService())->delOssFile($this->fileUrl);
        DB::table("{$this->pdfTable} as pdf")->where('id', $this->pdfId)->update([
            'book_catalog_id' => 0,
            'file_url'        => '',
            'file_size'       => 0,
            'origin_name'     => '',
            'deleted_at'      => now(),
        ]);
    }

}
